package com.contest.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.contest.entity.RoomInfo;
import com.contest.service.RoomInfoService;
import com.contest.util.DateUtil;
import com.contest.util.IdWorker;
import com.contest.util.PageUtils;
import com.contest.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.contest.entity.GameNumbersBettingType;
import com.contest.service.GameNumbersBettingTypeService;


/**
 * 
 *
 * @author yfl
 * @email 617823298@qq.com
 * @date 2018-05-17 14:57:27
 */

@Controller
@RequestMapping("/gameNumbersBettingType")
public class GameNumbersBettingTypeController {

    @Autowired
    GameNumbersBettingTypeService gameNumbersBettingTypeService;
    @Autowired
    IdWorker idWorker;

    @RequestMapping("/list")
    @ResponseBody
    public PageUtils list(@RequestParam Map<String,Object> param) {
        int page = Integer.parseInt(param.get("page").toString());
        int rows = Integer.parseInt(param.get("rows").toString());
        Page<GameNumbersBettingType> mPage = new Page<GameNumbersBettingType>(page, rows);
        mPage = gameNumbersBettingTypeService.selectPage(mPage);
        return new PageUtils(mPage.getRecords(),mPage.getTotal());
    }


    @RequestMapping("/clientList")
    @ResponseBody
    public List<GameNumbersBettingType> comboList(){
        List<GameNumbersBettingType> list = gameNumbersBettingTypeService.selectList(null);
        return list;
    }


    @PostMapping("/save")
    @ResponseBody
    public R save(GameNumbersBettingType gameNumbersBettingType) {
        gameNumbersBettingType.setFdId(idWorker.nextId() + "");
        gameNumbersBettingType.setFdCreatedTime(DateUtil.now());
        if (gameNumbersBettingTypeService.insert(gameNumbersBettingType)) {
            return R.ok("操作成功!");
        } else {
            return R.error("操作失败");
        }
    }

    @GetMapping("/edit/{fdId}")
    public String edit(Model model, @PathVariable("fdId") String fdId) {
        GameNumbersBettingType gameNumbersBettingType = gameNumbersBettingTypeService.selectById(fdId);
        model.addAttribute("gameNumbersBettingType", gameNumbersBettingType);
        return "gameNumbersBettingType/edit";
    }

    @PostMapping("/remove")
    @ResponseBody
    public R remove(@RequestParam("ids[]") String[] ids) {
        List<String> fdIds = new ArrayList<String>();
        for (String id : ids) {
            fdIds.add(id);
        }
        if (gameNumbersBettingTypeService.deleteBatchIds(fdIds)) {
            return R.ok("删除成功");
        } else {
            return R.error(-1, "删除失败!");
        }
    }

    @PostMapping("/update")
    @ResponseBody
    public R update(GameNumbersBettingType gameNumbersBettingType) {
        if (gameNumbersBettingTypeService.updateById(gameNumbersBettingType)) {
            return R.ok("更新成功!");
        } else {
            return R.error(-1, "更新失败!");
        }
    }

}
